﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Data;

namespace STAR.RunnerFramework
{
    public class TestHelper
    {
        public string TargetPath { get; set; }

        private RunnerBase _runnerBase;

        public TestHelper()
        {
            _runnerBase = new RunnerBase();
        }

        public void SetUp()
        {
            _runnerBase.TargetPath = this.TargetPath;
            _runnerBase.SetUp();
        }

        public void SetUp(Process process)
        {
            _runnerBase.SetUp(process);
        }

        public DataTable GetControlTable()
        {
            DataTable controlTable = new DataTable();
            DataColumn tabIndexColumn = new DataColumn();
            tabIndexColumn.ColumnName = "controlTabIndex";
            controlTable.Columns.Add(tabIndexColumn);

            DataColumn nameColumn = new DataColumn();
            nameColumn.ColumnName = "controlName";
            controlTable.Columns.Add(nameColumn);

            DataColumn valueColumn = new DataColumn();
            valueColumn.ColumnName = "controlValue";
            controlTable.Columns.Add(valueColumn);

            DataColumn kindColumn = new DataColumn();
            kindColumn.ColumnName = "controlCategory";
            controlTable.Columns.Add(kindColumn);

            int controlCount = _runnerBase.GetControlCount();

            SortedList<int, DataRow> newRows = new SortedList<int, DataRow>();

            for (int i = 0; i < controlCount; ++i)
            {
                ControlInfo info = _runnerBase.GetInfo(i);

                DataRow newRow;
                newRow = controlTable.NewRow();
                newRow["controlTabIndex"] = info.TabIndex;
                newRow["controlName"] = info.Name;
                newRow["controlValue"] = _runnerBase.GetText(info.Name);
                newRow["controlCategory"] = info.Category.ToString();
 
                newRows.Add(info.TabIndex, newRow);
            }

            for (int i = 0; i < controlCount; ++i)
            {
                controlTable.Rows.Add(newRows[i]);
            }
            return controlTable;
        }

    }
}
